<template>
  <div class="search_course_name">
    <el-select
      :value="className"
      filterable

			@change="selectName"
      placeholder="请输入课程关键词"
 
      :loading="loading"
    >
      <el-option
        v-for="item in classList"
        :key="item.id"
        :label="item.className"
        :value="item.id"
      >
      </el-option>
    </el-select>
  </div>
</template>

<script>
import {  getCourseByName } from "@/api/school/class";
export default {
	data() {
		return {
			className: '',
			classList: [],
			loading: false,
			open: false, 
      refId: ''
		}
	},
  created() {
    this.init()
  },
  methods: {
		init(e) {
			this.className = e ? e : ''
			this.classList = []
			this.loading = false
			this.open = false
      console.log(e, 'e')
      this.getCourseByName();
		},
		selectName(e) {
      // this.classList.forEach(item => {
      //   if (item.id == e) {
      //     console.log('进来了', item.id, e)
      //     this.className = item.className || item.courseName
      //   }
      // })
      // console.log(e, '选择课程')
      this.className = e;
			this.$emit('update', e)
		},
    
    getCourseByName(query) {
			this.loading = true
      getCourseByName({ name: query }).then((res) => {
        console.log(res);
				this.loading = false
        this.classList = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.search_course_name {
  width: 100%;
  height: 100%;
}
</style>